package ex.tableapi.aggregation;

import ex.tableapi.ApiFrame;
import org.apache.flink.table.api.Table;

import static org.apache.flink.table.api.Expressions.$;

public class ExGroupByAggregation extends ApiFrame {
    private String outName = "printOutTable";

    public static void main(String[] args) {
        ExGroupByAggregation demo = new ExGroupByAggregation();
        demo.getEnv();
        Table orders = demo.registerMysql("myorder", "orders");
        Table result = demo.exGroupByAggregation(orders);

        demo.registerConsole(demo.createPrintOutDDL(result.getResolvedSchema().toString()), demo.outName);
        result.executeInsert(demo.outName);
    }



    private Table exGroupByAggregation(Table orders) {
        //select a,sum(b) d from myorder m group by a
        Table result = orders.groupBy($("a")).select($("a"), $("b").sum().as("d"));
        return result;
    }

}